
package edu.moravian.entity;

import edu.moravian.math.Point2D;
import edu.moravian.math.Vector2D;
import edu.moravian.path.Path;

/**
 *
 * @author ronaghan
 */
public class Enemy extends Entity
{
    
    private Path path;
    private Point2D currentDestination;
    private double health;
    
    
    public Enemy(Point2D location, Vector2D velocity, double mass, double radius, double health, String type)
    {
        super(location, velocity, mass, radius, type);
        this.health = health;
    }
    

    public Enemy(Point2D location, Vector2D heading, double speed, double mass, double radius, double health, String type)
    {
        super(location, heading, speed, mass, radius, type);
        this.health = health;
    }
    
    public void setPath(Path path)
    {
        this.path = path;
        
        this.currentDestination = path.getNextDest();
        setHeading(currentDestination.minus(location).getNormalized());
    }
            
    public void setHealth(double health)
    {
        this.health = health;
    }
    
    public double getHealth()
    {
        return health;
    }
    
    public boolean reachedGoal()
    {
        return path.hasNextDest() == false;
    }
    
    /**
     * Agents move towards their current dest. If they have reached the dest the see if there
     * is a next dest and head towards that. 
     * 
     * @param delta 
     */
    @Override
    public void update(double delta)
    {
        if(location.distance(currentDestination) < radius)
        {
            if(path.hasNextDest())
            {
                currentDestination = path.getNextDest();
                setHeading(currentDestination.minus(location).getNormalized());
            }
            else
            {
                setHeading(new Vector2D());
            }
        }
        
        location.scalePlusEquals(speed*delta, heading); 
    }
    
    public void update(double delta, Iterable<Enemy> neighbors)
    {
        if(location.distance(currentDestination) < radius)
        {
            if(path.hasNextDest())
            {
                currentDestination = path.getNextDest();
                setHeading(currentDestination.minus(location).getNormalized());
            }
            else
            {
                setHeading(new Vector2D());
            }
        }
        
        location.scalePlusEquals(speed*delta, heading); 
    }
        
    
}
